<?php
include_once('inc/init.php');
include_once('inc/functions.index.php');
?>
<?php
// Define some variables.
$error_msg = "";
$name = stripslashes($_REQUEST['name']);
$email = stripslashes($_REQUEST['email']);
$subject = stripslashes($_REQUEST['subject']);
$message = stripslashes($_REQUEST['message']);
$sent = false;

// Verify if the form was sent.
if (isset($_REQUEST['action'])) {
  if (strlen($name)==0) {
    $error_msg .= "<p> '<strong>Your name</strong>' field is empty. </p>";
  }
  if (strlen($email)==0) {
    $error_msg .= "<p> '<strong>Your e-mail address</strong>' field is empty. </p>";
  } elseif (!isMail($email)) {
    $error_msg .= "<p> '<strong>Your e-mail address</strong>' is not valid. </p>";
  }
  if (strlen($subject)==0) {
    $error_msg .= "<p> '<strong>Subject</strong>' field is empty. </p>";
  }
  if (strlen($message)==0) {
    $error_msg .= "<p> '<strong>Message</strong>' field is empty. </p>";
  }
  // Send email
  if (strlen($error_msg)==0) {
    $to      = "atrandafirc@yahoo.com, freezemp@yahoo.com";
		$subject = '[TheFingerFor] [Feedback] '.$subject;
		$body    = $message;
		$headers = 'From: ' . FROM_EMAIL . "\r\n" .'Reply-To: ' . $email . "\r\n" .'X-Mailer: PHP/' . phpversion();
		mail($to, $subject, $body, $headers);
		$sent=true;
  }
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Feedback form - The Finger For</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<?php include_once('template/head.php');?> 
</head>

<body>
	<div id="wrap">
		<!-- header -->
		<?php include_once('template/header.php'); ?>
		<!-- body -->
		<div id="body">
			<?php include_once('template/subheader.php'); ?>
			<h1>Feedback form</h1>
			<div class="body">
			
			<?php 
			if ($sent): ?>
				<p class="form_item">
					Your message has been sent, wel'll get back to you as soon as possible!
				</p>
			<?php else: ?>
				<?php if (strlen($error_msg)>0) { ?>
					<div class="error">
						<?php echo $error_msg; ?>
					</div>
				<?php } ?>			
				<form name="login" action="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];?>" method="post">
          <p class="form_item">
            <span class="label"> Your name: </span>
            <span class="desc"> Nice to meet you! :) </span>
            <input value="<?php echo $name; ?>" type="text" name="name" class="inputwb wide3x" />
            <input type="hidden" name="action" value="feedback" />
          </p>
					<p class="form_item">
						<span class="label"> Your e-mail address: </span>
						<span class="desc"> Please enter your e-mail address. </span>
						<input value="<?php echo $email; ?>" type="text" name="email" class="inputwb wide3x" />
					</p>
          <p class="form_item">
						<span class="label"> Subject: </span>
						<span class="desc"> Short reason why you're writing to us. </span>
						<input value="<?php echo $subject; ?>" type="text" name="subject" class="inputwb wide3x" />
					</p>
          <p class="form_item">
						<span class="label"> Message: </span>
						<span class="desc"> Let us know how can we help you. </span>
						<textarea name="message" class="inputwb wide5x" rows="8" cols="60" style="font-size:14px;"><?php echo $message; ?></textarea>
					</p>
					<p class="form_item">
						<span class="desc">Send form!</span>
						<input type="submit" class="orange_btn" value="Submit" />
					</p>
				</form>
			<?php endif; ?>
				</div>
		</div>
		<!-- footer -->
		<?php include_once('template/footer.php'); ?>
	</div>
	<br /><br /> <!-- keep some space with the bottom -->
</body>
</html>
<?php mysql_close($db); ?>